﻿<Window x:Class="MSDNWebcast.Shell"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Controls="clr-namespace:MSDNWebcast.Controls"
        xmlns:local="clr-namespace:MSDNWebcast.Converter" 
        xmlns:Views="clr-namespace:MSDNWebcast.Views"
        xmlns:Commands="clr-namespace:MSDNWebcast.Commands"
        Title="MSDN Webcast 中文网络广播" Height="600" Width="960" WindowStartupLocation="CenterScreen">
    <Window.Resources>

        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

        <local:BackgroundViewportConverter x:Key="backgroundViewport" />

        <local:OpacityToVisibilityConverter x:Key="OpacityToVisibilityConverter" />

        <Storyboard x:Key="BackgroundChange" >
            <DoubleAnimation Duration="00:00:00.25" Storyboard.TargetName="mainBackground" Storyboard.TargetProperty="Opacity" From="0" To="1"/>
        </Storyboard>

        <Storyboard x:Key="BackgroundChange1">
            <DoubleAnimation Duration="00:00:00.25" BeginTime="00:00:00.25" Storyboard.TargetName="mainBackground" Storyboard.TargetProperty="Opacity" From="1" To="0"/>
        </Storyboard>

    </Window.Resources>
    <Window.Background>
        <ImageBrush ImageSource="Images\background.jpg" x:Name="backgroundImage" Stretch="UniformToFill" TileMode="Tile" ViewportUnits="Absolute"
                                Viewport="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}},  Path=ActualWidth, Converter ={StaticResource backgroundViewport}}" >
        </ImageBrush>
    </Window.Background>

    <Grid >
        <Grid.Background>
            <SolidColorBrush x:Name="mainBackground" Color="Black" Opacity="0"></SolidColorBrush>
        </Grid.Background>
        <Grid Name="body" Opacity="0" Margin="56,30,56,0" RenderTransformOrigin="0.5,0.5"
                                  Visibility="{Binding Path=ShowMainContent, Converter ={StaticResource BooleanToVisibilityConverter}}"  >
            <Grid.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=ShowMainContent}" Value="true">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:01" Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                                            <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:01" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                                            <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:01" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                                            <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
            <Grid.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Grid.RenderTransform>
            <Grid.RowDefinitions>
                <RowDefinition Height="47" />
                <RowDefinition Height="*" />
                <RowDefinition Height="40" />
            </Grid.RowDefinitions>

            <!--主体-->

            <Controls:AnimatedTabControl x:Name="mainTab" Grid.Row="0" Grid.RowSpan="2"
                                            Style="{StaticResource mainTab}" IsSynchronizedWithCurrentItem="True"
                                            ItemContainerStyle="{StaticResource mainTabItem}"
                                            SelectionChanging="TabControl_SelectionChanging">
                <TabItem Header="网络广播" IsSelected="{Binding CoursesView.IsActive}">
                    <ContentControl Content="{Binding Path=CoursesView}"/>
                </TabItem>
                <TabItem Header="下载管理" IsSelected="{Binding Downloads.IsActive}">
                    <ContentControl Content="{Binding Path=Downloads}"/>
                </TabItem>
                <TabItem x:Name="videoTab"  Header="视频播放" IsSelected="{Binding VideoPlayer.IsActive}">
                    <ContentControl x:Name="videoPlayer" Content="{Binding Path=VideoPlayer}"></ContentControl>
                </TabItem>
            </Controls:AnimatedTabControl>

            <!--LOGO-->
            <Image Margin="-35,-20,0,0" Source="Images/logo.png" Height="46" HorizontalAlignment="Left" VerticalAlignment="Top"></Image>

            <!--其他-->
            <TextBlock Grid.Row="2" x:Name="txtLink" Opacity="0.6" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,8,10">
                <Hyperlink Name="hyperlink" Foreground="White" NavigateUri="http://webcast.codeplex.com" Command="Commands:GlobalCommands.OpenUrl" CommandParameter="{Binding Path = NavigateUri, Source=hyperlink}">
                  http://webcast.codeplex.com
                </Hyperlink>
            </TextBlock>
        </Grid>

        <Views:Loading x:Name="loading"  Content="{Binding Path=Loading}" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Opacity, Converter ={StaticResource OpacityToVisibilityConverter}}" 
                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Margin="56,30,56,40" Grid.RowSpan="2">
            <Views:Loading.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=ShowLoading}" Value="false">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                                            <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Views:Loading.Style>
        </Views:Loading>
    </Grid>
</Window>